-- example: type class (qualified notation) -- |
|
library ieee;
use ieee.std_logic_1164.all;
package element_pack_typeclass is
type Element is class
class attribute Value: integer;
impure function get_value return integer;
impure function equal(Other: Element'CLASS) return boolean;
end class Element;
type Element is class body
impure function get_value return integer is
begin
return Value;
end;
impure function equal(Other: Element'CLASS) return boolean is
begin
return (Value = Other.get_value);
end;
end class body Element;
|
base class |
type Child_Of_Element is new class Element with
impure function equal (Other: Element'CLASS) return boolean;
end class Child_Of_Element;
type Child_Of_Element is class body
impure function equal(Other: Element'CLASS) return boolean is
-- redefines former method "equal"
begin
return (Value = Other.get_value + 5);
end;
impure function different(Other: Element'CLASS) return boolean is
begin
return not Element.equal(Other);
-- get access to former method "equal"
end;
end class body Child_Of_Element;
end package;
|
derived classes |